import configparser
from src.net import Server
import src.util as util
import src.global_config as gl
import os
from src.log import Log

# 配置文件地址
filename = './config.ini'

if __name__ == '__main__':
    # 读取程序配置
    config = configparser.ConfigParser()
    config.read(filename, encoding='utf-8')
    port = config['tcp']['port']

    # 设置全局变量
    dbpath = os.path.dirname(os.path.realpath(__file__))
    gl.set_value('logpath', dbpath)
    gl.set_value('db_config', config['db'])
    gl.set_value('mct_config', config['mcts'])
    log = Log()
    # 没有端口就抛出错误
    if port is None:
        log.crit("缺少端口号")
        print(format(util.LACK_OF_PARAMS, 'port'))

    net = Server()
    net.run(port)
